﻿using Basic.FormGatewaryModular.Interface;
using Basic.FormGatewaryModular.Model.Form;
using Basic.FormRemoteModel;
using Basic.FormRemoteModel.Form;
using Basic.FormRemoteModel.Form.Model;
using WeDonekRpc.Client;
using WeDonekRpc.HttpApiGateway.Model;

namespace Basic.FormGatewaryModular.Services
{
    internal class FormService : IFormService
    {
        public long Add ( FormAdd datum )
        {
            return new AddForm
            {
                Datum = datum,
            }.Send();
        }
        public void SetLayoutType ( long id, FormLayoutType layoutType )
        {
            new SetFormLayoutType
            {
                Id = id,
                Layout = layoutType
            }.Send();
        }
        public FormOutline GetOutline ( long id, PyFormPageType pageType )
        {
            return new GetFormOutline
            {
                Id = id,
                PageType = pageType,
            }.Send();
        }
        public void SyncPhyBody ( long id )
        {
            new SyncPhyFormBody
            {
                Id = id,
            }.Send();
        }
        public StructureColumn GetStructure ( StructureGetArg arg )
        {
            return new GetFormStructure
            {
                FormId = arg.FormId,
                Param = new FormGetParam
                {
                    TableId = arg.TableId,
                    FuncType = arg.FuncType,
                    DataType = arg.DataType,
                    ShowMode = arg.ShowMode,
                    IsSystem = arg.IsSystem
                }
            }.Send();
        }
        public StructureColumn[] GetStructures ( StructureGetArgs arg )
        {
            return new GetFormStructures
            {
                FormId = arg.FormId,
                Param = new FormGetParam
                {
                    TableId = arg.TableId,
                    FuncType = arg.FuncType,
                    DataType = arg.DataType,
                    ShowMode = arg.ShowMode,
                    IsSystem = arg.IsSystem
                }
            }.Send();
        }
        public FormBody GetBody ( long id )
        {
            return new GetFormBody
            {
                Id = id,
            }.Send();
        }

        public void Delete ( long id )
        {
            new DeleteForm
            {
                Id = id,
            }.Send();
        }

        public FormDto Get ( long id )
        {
            return new GetForm
            {
                Id = id,
            }.Send();
        }

        public PagingResult<FormDto> Query ( PagingParam<FormQuery> query )
        {
            return new QueryForm
            {
                Query = query.Query,
                Index = query.Index,
                Size = query.Size,
                NextId = query.NextId,
                SortName = query.SortName,
                IsDesc = query.IsDesc
            }.Send();
        }

        public bool Set ( long id, FormSet datum )
        {
            return new SetForm
            {
                Id = id,
                Datum = datum,
            }.Send();
        }

        public void Stop ( long id )
        {
            new StopForm
            {
                Id = id,
            }.Send();
        }
        public bool Enable ( long id )
        {
            return new EnableForm
            {
                Id = id,
            }.Send();
        }

        public FormTable[] GetTable ( long formId )
        {
            return new GetFormTable
            {
                FormId = formId,
            }.Send();
        }

        public FormColumn[] GetColumns ( FormColGetArg arg )
        {
            return new GetFormColumns
            {
                Arg = arg,
            }.Send();
        }
    }
}
